package com.hooper.hosp.controller.api;

import com.hooper.hosp.model.hosp.Hospital;
import com.hooper.hosp.service.DepartmentService;
import com.hooper.hosp.service.HospService;
import com.hooper.hosp.service.ScheduleService;
import com.hooper.hosp.vo.DepartmentVo;
import com.hooper.hosp.vo.hosp.HospitalQueryVo;
import com.hooper.hosp.vo.hosp.ScheduleOrderVo;
import com.hooper.hospital.common.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @author Tim Hooper
 * @version 1.0
 * @time 2022/10/03/0:39
 */
@Api(value = "api for the foreground system ")
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/hosp/front")
public class FrontHospApiController {

    private final HospService hospService;
    private final DepartmentService departmentService;
    private final ScheduleService scheduleService;

    @ApiOperation(value = "get hosp page by conditions")
    @GetMapping("/hospPage/{currentPage}/{pageSize}")
    public Result<Page<Hospital>> getHospPage(@PathVariable Integer currentPage,
                                              @PathVariable Integer pageSize,
                                              HospitalQueryVo hospitalQueryVo) {
        Page<Hospital> hospitals = hospService.pageByConditions(currentPage, pageSize, hospitalQueryVo);
        return Result.ok(hospitals);
    }

    @ApiOperation("find hosp list by a fuzzy name")
    @GetMapping("{hosname}")
    public Result<List<Hospital>> findByName(@PathVariable String hosname) {
        List<Hospital> hospitalList = hospService.findLikeName(hosname);
        return Result.ok(hospitalList);
    }

    @ApiOperation("get the departments which belong to the hoscode")
    @GetMapping("/department/{hoscode}")
    public Result<List<DepartmentVo>> getDepartments(@PathVariable String hoscode) {
        return Result.ok(departmentService.getDepartmentListByHoscode(hoscode));
    }

    @ApiOperation("get schedules by hoscode")
    @GetMapping("/hospInfo/{hoscode}")
    public Result getHospInfo(@PathVariable String hoscode) {
        return Result.ok(hospService.getHospInfo(hoscode));
    }

    @ApiOperation(value = "根据排班id获取预约下单数据")
    @GetMapping("inner/getScheduleOrderVo/{scheduleId}")
    public ScheduleOrderVo getScheduleOrderVo(
            @ApiParam(name = "scheduleId", value = "排班id", required = true)
            @PathVariable("scheduleId") String scheduleId) {
        return scheduleService.getScheduleOrderVo(scheduleId);
    }
}
